import util
from eventServer import eventServer

class Action:
    def __init__(self, name, object):
        self.name = name
        self.object = object
        self.dead = False
        
        self.receiveFunctions = util.getFunctions(self,"receive_")
        for cmd, f in self.receiveFunctions.iteritems():
            eventServer.subscribe(cmd,f)
            
        self.localPublish = eventServer.localPublish
        self.publish = eventServer.publish
        self.subscribe = eventServer.subscribe
            
    def stop(self):
        if not self.dead:
            self.log("stop")
            self.dead = True
            self.kill()
            for cmd, f in self.receiveFunctions.iteritems():
                eventServer.unsubscribe(cmd,f)
            
    def run(self, args):
        pass
    
    def kill(self):
        pass
    
    def log(self, *v):
        print "%s(%s): %s" % (self.object.name, self.name, ' '.join(map(str,v)))
